<%@ include file="/WEB-INF/view/include.jsp"%>


<div class="t_tmiddle-right">
	<div id="tabs">
      <ul id="TabHeader">
        <li><a href="#ApplicationDetails"><spring:message code="header.app.details" /></a></li>
      </ul>
		<form:form modelAttribute="evTerminationModel" name="evTerminationModel"
			id="evTerminationModel" method="POST" enctype="multipart/form-data"
			class="t_form" action="client/company/evterminate/mainadmin/form.htm?appId=${appId}">
			<spring:hasBindErrors name="evTerminationModel">
				<script type="text/javascript">
					$(document)
							.ready(
									function() {
										jAlert(
												'error',
												'<li><form:errors path="*" delimiter="<li>"/>',
												'<spring:message code="label.errormessage" />');
									});
				</script>
			</spring:hasBindErrors>
				
			<table  style="width: 100%">
		    	<tr height="5px;"><td colspan="3"></td></tr>
		    	<tr><td width="20%"></td><td align="center"><div class="t_gin-grey-txt"><spring:message code="label.wfstatus" />${evTerminationModel.wfStatus}</div></td><td width="20%"></td></tr>
		    </table>
			<%@include file="AppDetails.jsp"%>
		
		</form:form>
	</div>
</div>
<!--Middle Right Close-->
<script>

	var submAction = null;
	
	function setAction(inaction){
		submAction = inaction;
	}
	function submitForm(divId){
		$('#evTerminationModel').append($("#"+divId).html());
		var input = $("<input>").attr("type", "hidden").attr("name", "MainUserApprove").val("MainUserApprove");
		$('#evTerminationModel').append($(input));
		$.fancybox.showLoading();
		$('#evTerminationModel').submit();
	}
	//Validation - Required fields
	$()
			.ready(
					function() {
						//CLOSING POPUP
						//Click the x event!
						$("#popupContactClose").click(function() {
							disablePopup();
						});
						//Click out event!
						$("#backgroundPopup").click(function() {
							disablePopup();
						});
						//Press Escape event!
						$(document).keypress(function(e) {
							if (e.keyCode == 27 && popupStatus == 1) {
								disablePopup();
							}
						});
						
						$("#evTerminationModel").validate({

							onfocusout:false,
							onkeyup:false,
							onclick: false,			
							rules : {
								//Employee Details
								fnpServiceCode : {
									required : {
										depends: function(element) {
								           return submAction == "submit";
								        }
									}
								},
								adminComments : {
									required : {
										depends: function(element) {
								           return submAction == "reject";
								        }
									}
								}
							},
							
							submitHandler: function (form) {
								blockPage();
								form.submit();
							},
							
							showErrors : function(errorMap, errorList) {
								
								var errors = '<ul>';
								var label;				
								if (errorList.length) {
									$.each(errorMap, function(name, value) {
										label = $("label[for='" + name + "']").html();
										label = value + '[' + label + ']';
										errors = errors + '<li>' + label + '</li>';
										

									});
									errors = errors + '</ul>';
									jAlert('error', errors, '<spring:message code="label.errormessage" />');
									return false;
								}
							}		
						});
						
						$tabs = $("#tabs").tabs();	
						$('#TabHeader').removeClass('ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all');
						$('#TabHeader > li').removeClass('ui-state-default ui-corner-top ui-state-active ui-state-hover');
						$('#tabs').removeClass('ui-widget ui-widget-content ui-corner-all');
						
						$('#tabs').tabs({
							select : function(event, ui) {
								
								var selected = $tabs.tabs('option', 'selected'); // => 0
								var clicked = ui.index; // => 0
													
								if( selected > clicked )
									return true;
								
								return true;
							}
						});
						
						$('#AppDet-Next').click(function() { // bind click event to link			
							$tabs.tabs('select', 1);
							return false;
							//$('#EmploymentVisaFrm').submit();
						});
						
						$('#SubDet-Prev').click(function() { // bind click event to link			
							$tabs.tabs('select', 0);
							return false;
						});
						
						
					});

	
	

	function validate() {
		return ($("#evTerminationModel").validate().element("#fnpServiceCode"));
	}
	
	jQuery(document).ready(
			function() {
				EmployeeAutoFiller.init("evcEmployeeId");
				EmployeeAutoFiller.defineFieldMapping("empNameEn",
				"empName");
				EmployeeAutoFiller.defineFieldMapping("empPostNo",
						"empPostNoMap");
				EmployeeAutoFiller.defineFieldMapping("empNationality",
						"empNationalityMap");
				EmployeeAutoFiller.defineFieldMapping("empCECNo",
						"empCECNoMap");
				EmployeeAutoFiller.defineFieldMapping("empNameAr",
						"empNameAr");
				EmployeeAutoFiller.fillFields();
			});
	
	function cancelForm(divId){
		fancyConfirm('<spring:message code="message.cancel_confirmation_message" />'
				,'<spring:message code="button.No" />'
				,'<spring:message code="button.yes" />'
				, function(ret) {
					if(ret == true){
						//cancel
						var input = $("<input>").attr("type", "hidden").attr("name", "MainUserCancel").val("MainUserCancel");
						$('#evTerminationModel').append($(input));
						$('#evTerminationModel').submit();
						$.fancybox.showLoading();
					}
		});
	}
</script>